//
//  ZJCourseCommentAndCollectView.m
//  ZhongWangYuanApp
//
//  Created by ZJ on 2018/6/3.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZJCourseCommentAndCollectView.h"

@interface ZJCourseCommentAndCollectView ()
/** 收藏按钮 */
@property (nonatomic, strong) UIButton *collect;
/** 评论按钮 */
@property (nonatomic, strong) UIButton *comment;
@end

@implementation ZJCourseCommentAndCollectView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    self.backgroundColor = [UIColor zj_colorWithHexString:@"f0f0f0"];
    [self addSubview:self.collect];
    [self addSubview:self.comment];
    self.collect.sd_layout
    .topSpaceToView(self, 1)
    .leftEqualToView(self)
    .bottomEqualToView(self)
    .widthIs(125 * [UIScreen zj_screenWScale]);
    
    self.comment.sd_layout
    .topEqualToView(self.collect)
    .leftSpaceToView(self.collect, 0)
    .bottomEqualToView(self)
    .rightEqualToView(self);
    
}

#pragma mark -  点击事件
//收藏
- (void)action_Collect:(UIButton *)sender{
    if (sender.isSelected) {//选中状态。已经收藏：点击执行取消收藏
        if(self.delelgate){
            [self.delelgate ZJCourseCommentAndCollectViewDelegate_cancelCollect];
        }
    }else{//未选中状态。收藏：点击执行收藏
        if(self.delelgate){
            [self.delelgate ZJCourseCommentAndCollectViewDelegate_collect];
        }
    }
}
//评价
- (void)action_Comment:(UIButton *)sender{
    if (sender.isSelected) {//选中状态，已评价
        return;
    }
    if (self.delelgate) {
        [self.delelgate ZJCourseCommentAndCollectViewDelegate_comment];
    }
}

#pragma mark - 方法
- (void)setCollectButtonIsCollect:(BOOL)isCollect{
    self.collect.selected = isCollect;
}

- (void)setCommentButtonIsComment:(BOOL)isComment model:(LPZWYChooseClassClassModel *)model{
    if (model.ifenablecomment && ([model.ifenablecomment integerValue] == 0)) {//是国家领导人
        self.comment.backgroundColor = [UIColor lightGrayColor];
        [self.comment setTitle:@"评价" forState:UIControlStateSelected];
        self.comment.selected = YES;
    }else{//不是国家领导人
        [self.comment setTitle:@"评价" forState:UIControlStateNormal];
        [self.comment setTitle:@"已评价" forState:UIControlStateSelected];
        self.comment.backgroundColor = [UIColor themeColor];
        self.comment.selected = isComment;
    }
}

#pragma mark - Setter


#pragma mark - Getters
- (UIButton *)collect{
    if (_collect == nil){
        _collect = [UIButton new];
        [_collect setTitleColor:[UIColor zj_colorWithHexString:@"999999"] forState:UIControlStateNormal];
        [_collect setTitle:@"收藏" forState:UIControlStateNormal];
        [_collect setTitle:@"取消收藏" forState:UIControlStateSelected];
        _collect.titleLabel.font = LYPFONT(18);
        _collect.backgroundColor = [UIColor themeWhiteColor];
        [_collect addTarget:self action:@selector(action_Collect:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _collect;
}
- (UIButton *)comment{
    if (_comment == nil){
        _comment = [UIButton new];
        [_comment setTitleColor:[UIColor themeWhiteColor] forState:UIControlStateNormal];
        [_comment setTitle:@"评价" forState:UIControlStateNormal];
        [_comment setTitle:@"已评价" forState:UIControlStateSelected];
        _comment.titleLabel.font = self.collect.titleLabel.font;
        _comment.backgroundColor = [UIColor themeColor];
        [_comment addTarget:self action:@selector(action_Comment:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _comment;
}

@end
